import cv2
import numpy as np
import os

RECOGNIZER = cv2.face.LBPHFaceRecognizer_create()
PASS_CONF = 45
FACE_CASCADE = cv2.CascadeClassifier(os.getcwd() + "\\cascades\\haarcascade_frontalface_default.xml")

#训练器识别
def train(photos, lables):
    """

    :param photos:
    :param lables:
    :return:
    """
    RECOGNIZER.train(photos, np.array(lables))

#判断图像中是否有正面人脸
def found_face(gary_img):
    faces = FACE_CASCADE.detectMultiScale(gary_img, 1.15, 4)
    return len(faces) > 0

#识别器识别图像中的人脸
def recongnise_face(photo):
    label, confidence = RECOGNIZER.predict(photo)
    if confidence > PASS_CONF:
        return -1
    return label